package com.xyh.backend3;

import com.xyh.backend3.pojo.CompareResult;
import com.xyh.backend3.pojo.Db;
import com.xyh.backend3.tool.DbComparator;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import java.io.IOException;
import java.util.Properties;

public class App {
    public static void main(String[] args) throws IOException {
        // 加载配置文件
        Properties props = PropertiesLoaderUtils.loadProperties(new ClassPathResource("application.yaml"));

        // 数据库配置
        Db db1 = new Db(
                (String) props.get("databases.db1.driverClassName"),
                (String) props.get("databases.db1.url"),
                (String) props.get("databases.db1.username"),
                (String) props.get("databases.db1.password")
        );

        Db db2 = new Db(
                (String) props.get("databases.db2.driverClassName"),
                (String) props.get("databases.db2.url"),
                (String) props.get("databases.db2.username"),
                (String) props.get("databases.db2.password")
        );

        // 比较
        DbComparator comparator = new DbComparator();
        CompareResult result = comparator.compare(db1, db2);

        System.out.println("表的不同: " + result.getTableDiffs());
        System.out.println("列的不同: " + result.getColumnDiffs());
    }
}